package com.example.covid19.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.example.covid19.config.SchedulingConfig;

import com.example.covid19.entity.Dynamique;
import com.example.covid19.service.DynamiqueService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ScheduledTask {

    private final DynamiqueService sysCronService;
    private final SchedulingConfig schedulingConfig;

    public ScheduledTask(DynamiqueService sysCronService, SchedulingConfig schedulingConfig) {
        this.sysCronService = sysCronService;
        this.schedulingConfig = schedulingConfig;
    }


    @Scheduled(cron = "10 * * * * ?")
    public void doRefresh() {
        List<Dynamique> sysCronList = sysCronService.list(
                new QueryWrapper<Dynamique>().eq("is_enable", 1)
        );
        schedulingConfig.refresh(sysCronList);
    }
}
